+2006-12-19 Mikael Hallendal <micke@imendio.com>
+
+ * gdk/quartz/gdkcursor-quartz.c: Splitted out the GdkPixbuf to NSImage
+ routine so that it can be used from libgtk as well (needed for
+ upcoming GtkStatusIcon support in the Quartz port).
+ * gdk/quartz/gdkevents-quartz.c: Don't assume that all NSWindows are
+ created from GDK, this is not true for the status icon.
+ * gdk/quartz/gdkprivate-quartz.h:
+ * gdk/quartz/gdkquartz.h: Added
+ gdk_quartz_pixbuf_to_ns_image_libgtk_only so that it is available to
+ the status icon code.
+
2006-12-16 Tristan Van Berkom <tvb@gnome.org>
* gtk/gtkmessagedialog.c: Added return_if_fail (image) to
return cursor;
}
-GdkCursor *
-gdk_cursor_new_from_pixbuf (GdkDisplay *display,
- GdkPixbuf *pixbuf,
- gint x,
- gint y)
+NSImage *
+_gdk_quartz_pixbuf_to_ns_image (GdkPixbuf *pixbuf)
{
- NSAutoreleasePool *pool;
- NSBitmapImageRep *bitmap_rep;
- NSImage *image;
- NSCursor *nscursor;
- GdkCursor *cursor;
- gboolean has_alpha;
- g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
- g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
- g_return_val_if_fail (0 <= x && x < gdk_pixbuf_get_width (pixbuf), NULL);
- g_return_val_if_fail (0 <= y && y < gdk_pixbuf_get_height (pixbuf), NULL);
-
- pool = [[NSAutoreleasePool alloc] init];
-
+ NSBitmapImageRep *bitmap_rep;
+ NSImage *image;
+ gboolean has_alpha;
+
has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
-
+
/* Create a bitmap image rep */
bitmap_rep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
- pixelsWide:gdk_pixbuf_get_width (pixbuf)
- pixelsHigh:gdk_pixbuf_get_height (pixbuf)
- bitsPerSample:8 samplesPerPixel:has_alpha ? 4 : 3
- hasAlpha:has_alpha isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace
- bytesPerRow:0 bitsPerPixel:0];
-
+ pixelsWide:gdk_pixbuf_get_width (pixbuf)
+ pixelsHigh:gdk_pixbuf_get_height (pixbuf)
+ bitsPerSample:8 samplesPerPixel:has_alpha ? 4 : 3
+ hasAlpha:has_alpha isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace
+ bytesPerRow:0 bitsPerPixel:0];
+
{
/* Add pixel data to bitmap rep */
guchar *src, *dst;
int src_stride, dst_stride;
int x, y;
-
+
src_stride = gdk_pixbuf_get_rowstride (pixbuf);
dst_stride = [bitmap_rep bytesPerRow];
-
+
for (y = 0; y < gdk_pixbuf_get_height (pixbuf); y++)
{
src = gdk_pixbuf_get_pixels (pixbuf) + y * src_stride;
dst = [bitmap_rep bitmapData] + y * dst_stride;
-
+
for (x = 0; x < gdk_pixbuf_get_width (pixbuf); x++)
{
if (has_alpha)
{
guchar red, green, blue, alpha;
-
+
red = *src++;
green = *src++;
blue = *src++;
alpha = *src++;
-
+
*dst++ = (red * alpha) / 255;
*dst++ = (green * alpha) / 255;
*dst++ = (blue * alpha) / 255;
*dst++ = alpha;
}
else
- {
- *dst++ = *src++;
- *dst++ = *src++;
- *dst++ = *src++;
- }
+ {
+ *dst++ = *src++;
+ *dst++ = *src++;
+ *dst++ = *src++;
+ }
}
}
}
-
+
image = [[NSImage alloc] init];
[image addRepresentation:bitmap_rep];
[bitmap_rep release];
+ [image autorelease];
+
+ return image;
+}
+GdkCursor *
+gdk_cursor_new_from_pixbuf (GdkDisplay *display,
+ GdkPixbuf *pixbuf,
+ gint x,
+ gint y)
+{
+ NSImage *image;
+ NSCursor *nscursor;
+ GdkCursor *cursor;
+ gboolean has_alpha;
+ g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
+ g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
+ g_return_val_if_fail (0 <= x && x < gdk_pixbuf_get_width (pixbuf), NULL);
+ g_return_val_if_fail (0 <= y && y < gdk_pixbuf_get_height (pixbuf), NULL);
+
+ GDK_QUARTZ_ALLOC_POOL;
+ has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
+
+ image = _gdk_quartz_pixbuf_to_ns_image (pixbuf);
nscursor = [[NSCursor alloc] initWithImage:image hotSpot:NSMakePoint(x, y)];
- [image release];
cursor = gdk_quartz_cursor_new_from_nscursor (nscursor, GDK_CURSOR_IS_PIXMAP);
- [pool release];
+ GDK_QUARTZ_RELEASE_POOL;
return cursor;
}
/* FIXME: Implement */
return NULL;
}
+
+NSImage *
+gdk_quartz_pixbuf_to_ns_image_libgtk_only (GdkPixbuf *pixbuf)
+{
+ return _gdk_quartz_pixbuf_to_ns_image (pixbuf);
+}
if (!nswindow)
return NULL;
-
+
+ /* Window where not created by GDK so the event should be handled by Quartz */
+ if (![[nswindow contentView] isKindOfClass:[GdkQuartzView class]])
+ return NULL;
+
if (event_type == NSMouseMoved ||
event_type == NSLeftMouseDragged ||
event_type == NSRightMouseDragged ||
GdkWindow *mouse_window;
point = [nsevent locationInWindow];
-
toplevel = [(GdkQuartzView *)[nswindow contentView] gdkWindow];
-
+
mouse_window = _gdk_quartz_find_child_window_by_point (toplevel, point.x, point.y, x, y);
synthesize_crossing_events (mouse_window, GDK_CROSSING_NORMAL, nsevent, *x, *y);
{
if (current_event)
{
- if (!gdk_event_translate (current_event))
+ if (!gdk_event_translate (current_event))
[NSApp sendEvent:current_event];
-
+
[current_event release];
current_event = NULL;
}